//
//  CSYTabbar.swift
//  CSYMicroBlockSina
//
//  Created by 姚彦兆 on 15/11/8.
//  Copyright © 2015年 姚彦兆. All rights reserved.
//

import UIKit

class CSYTabbar: UITabBar {

    //布局TabBar按钮
    override func layoutSubviews() {
        
        super.layoutSubviews()
        
        var index : CGFloat = 0
        
        let btn_W = self.bounds.size.width / 5
        
        let btn_H = self.bounds.height
        
        let rect = CGRectMake(0, 0, btn_W, btn_H)
        
        for subView in subviews {
        
            if(subView.isKindOfClass(NSClassFromString("UITabBarButton")!)){
            
                subView.frame = CGRectOffset(rect, btn_W * index, 0 )
            
                index += index == 1 ? 2 : 1
                
            }
            
        }
        
        commpentBtn.frame = CGRectOffset(rect, btn_W * 2 , 0)
        
        
        
        bringSubviewToFront(commpentBtn)
        
    }
    
    func setUpUI(){
    
        addSubview(commpentBtn)
        
        commpentBtn.layer.cornerRadius = 12
        
        commpentBtn.layer.masksToBounds = true
        
        commpentBtn.clipsToBounds = true
    
    }
    
    override init(frame: CGRect) {
        
        super.init(frame: frame)
        
        setUpUI()
        
    }

    required init?(coder aDecoder: NSCoder) {
//        fatalError("init(coder:) has not been implemented")
        
        super.init(coder: aDecoder)
        
        setUpUI()
        
    }
    
    //添加发布微博按钮按钮
    
    lazy var commpentBtn : UIButton = {
    
        let btn = UIButton ()
        
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        
        btn.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        
        btn.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        
        btn.sizeToFit()
        
        return btn
    
    }()
    

}
